| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344 |
| /**
* @ngdoc directive
* @name patternfly.canvas.component:pfCanvasEditor
* @restrict E
*
* @description
* Component for canvas editor which adds a toolbox where items can be dragged and dropped onto canvas, as well as other canvas
* operations such as: Zoom In, Zoom Out, Hide Connections, Remove Node, and Duplicate Node. Does not work in IE 11 or lower because they do not support
* latest svg specification's 'foreignObject' api. Tested in FireFox, Chrome, and MS-Edge.
*
* @param {object} chartDataModel Chart data object which defines the nodes and connections on the canvas. See {@link patternfly.canvas.component:pfCanvas} for detailed information.
* @param {object} chartViewModel (Optional) The chartViewModel is initialized from the chartDataModel and contains additional helper methods such as <code>chartViewModel.isOnlyOneNodeSelected()</code> and
* <code>chartViewModel.getSelectedNodes()</code>.
* @param {boolean} toolboxTabs An array of Tab objects used in the Toolbox. Each Tab object many contain 'subtabs' and/or 'items'. Items may be dragged onto the canvas.
* <ul style='list-style-type: none'>
* <li>.preTitle - (string) (Optional) A small title above the main tab title
* <li>.title - (string) The main title of the tab
* <li>.subtabs - (Array) An array of sub Tab objects. Supports up to three levels of nested sub tabs
* <li>.items - (Array) An array of items which can be dragged and dropped onto the canvas
* <ul style='list-style-type: none'>
* <li>.name - (string) The item name/title
* <li>.id - (number) The item id
* <li>.image - (string) (Optional) The url of the item's image. Ex: "/img/kubernetes.svg"
* <li>.icon - (string) (Optional) The icon class of the item's icon. Ex: "pf pficon-service"
* </ul>
* </ul>
* @param {boolean} readOnly (Optional) A flag indicating whether the canvas is in 'read-only' mode. When in 'read-only' mode nodes cannot be moved, selected, or deleted, and the node action toolbar is hidden.
* @example
<example module="patternfly.canvaseditor.demo">
<file name="index.html">
<style>
.canvas {
background-image: url('/img/canvas-dot-grid.png');
background-repeat: repeat;
}
</style>
<div ng-controller="CanvasEditorDemoCtrl" class="example-container">
<pf-canvas-editor chart-data-model="chartDataModel"
chart-view-model="chartViewModel"
toolbox-tabs="toolboxTabs"
read-only="readOnly">
<span ng-if="!readOnly" class="more-actions">
<a id="duplicateItem" ng-click="duplicateNode()" ng-class="{'disabled': !chartViewModel.isOnlyOneNodeSelected() || chartViewModel.inConnectingMode}">
<span class="pficon fa fa-copy"
tooltip-append-to-body="true" tooltip-placement="bottom"
uib-tooltip="{{'Duplicate Item'}}">
</span>
</a>
<a id="deleteNodes" ng-click="deleteNodes()" ng-class="{'disabled': !chartViewModel.areAnyNodesSelected() || chartViewModel.inConnectingMode}">
<span class="pficon pficon-delete"
tooltip-append-to-body="true" tooltip-placement="bottom"
uib-tooltip="{{'Delete Selected Items'}}">
</span>
</a>
</span>
</pf-canvas-editor>
<hr>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" ng-model="readOnly">Read Only</input>
</label>
</div>
<div style="padding-top: 12px;">
<label style="font-weight:normal;vertical-align:middle;">Events: </label>
</div>
<div>
<textarea rows="10" class="col-md-12">{{eventText}}</textarea>
</div>
</div>
</file>
<file name="modules.js">
angular.module('patternfly.canvaseditor.demo', ['patternfly.canvas']);
</file>
<file name="script.js">
angular.module( 'patternfly.canvaseditor.demo' ).controller( 'CanvasEditorDemoCtrl', function( $scope, $filter, $window ) {
var imagePath = $window.IMAGE_PATH || "img";
$scope.chartDataModel = {
"nodes": [
{
"name": "Nuage",
"x": 345,
"y": 67,
"id": 1,
"image": imagePath + "/OpenShift-logo.svg",
"width": 150,
"bundle": true,
"backgroundColor": "#fff",
"inputConnectors": [
{
"name": "Network",
"type": "network",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue909"
},
{
"name": "Container",
"type": "container",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue621"
}
],
"validConnectionTypes": ["network", "container"]
},
{
"name": "Vmware",
"x": 100,
"y": 290,
"id": 2,
"image": imagePath + "/kubernetes.svg",
"width": 150,
"backgroundColor": "#fff",
"validConnectionTypes": ["storage"],
"inputConnectors": [
{
"name": "Network",
"type": "network",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue909"
},
{
"name": "Storage",
"type": "storage",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue90e"
},
{
"name": "Container",
"type": "container",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue621"
}
]
},
{
"name": "NetApp",
"x": 350,
"y": 291,
"id": 3,
"width": 150,
"icon": "pf pficon-service",
"fontSize": "76px",
"backgroundColor": "#fff",
"inputConnectors": [
{
"name": "Network",
"type": "network",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue909"
},
{
"name": "Container",
"type": "container",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue621"
}
],
"validConnectionTypes": ["network"]
},
{
"name": "OpenShift",
"x": 105,
"y": 67,
"id": 4,
"width": 150,
"fontFamily": "fontawesome",
"fontContent": "\uf0c2",
"backgroundColor": "#fff",
"inputConnectors": [
{
"name": "Storage",
"type": "storage",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue90e"
},
{
"name": "Container",
"type": "container",
"fontFamily": "PatternFlyIcons-webfont",
"fontContent": "\ue621"
}
],
"validConnectionTypes": ["network", "container", "storage"]
}
],
"nodeActions" : [
{
"id": 1,
"name": "connect",
"iconClass": "fa fa-share-alt",
"action": "nodeActionConnect"
},
{
"id": 2,
"name": "edit",
"iconClass": "pf pficon-edit",
"action": "nodeActionEdit"
},
{
"id": 3,
"name": "tag",
"iconClass": "fa fa-tag",
"action": "nodeActionTag"
}
],
"connections": [
{
"source": {
"nodeID": 4,
"connectorIndex": 0
},
"dest": {
"nodeID": 1,
"connectorIndex": 1
}
},
{
"source": {
"nodeID": 4,
"connectorIndex": 0
},
"dest": {
"nodeID": 3,
"connectorIndex": 0
}
}
]
};
$scope.toolboxTabs = [
{
"preTitle": "Toolbox",
"title": "Items A",
"active": true,
"items": [
{
"name": "Nuage",
"id": 10000000000004,
"image": imagePath + "/OpenShift-logo.svg"
},
{
"name": "Vmware",
"id": 10000000000010,
"image": imagePath + "/kubernetes.svg"
}
]
},
{
"preTitle": "Toolbox",
"title": "Items B",
"active": true,
"items": [
{
"name": "NetApp",
"id": 10000000000014,
"icon": "pf pficon-service"
},
{
"name": "OpenShift",
"id": 10000000000021,
"icon": "fa fa-cloud"
},
{
"name": "OpenStack",
"id": 10000000000022,
"icon": "pf pficon-network"
},
{
"name": "Storage",
"id": 10000000000026,
"icon": "pf pficon-storage-domain"
},
{
"name": "VM",
"id": 10000000000023,
"icon": "pf pficon-virtual-machine"
},
{
"name": "Replicatore",
"id": 10000000000027,
"icon": "pf pficon-replicator"
}
]
}
];
$scope.readOnly = false;
$scope.eventText = "";
$scope.$on('nodeActionClicked', function(evt, args) {
var action = args.action;
var node = args.node;
$scope.eventText = node.name() + ' ' + action + '\r\n' + $scope.eventText;
});
$scope.deleteNodes = function() {
if ($scope.chartViewModel.inConnectingMode) {
return;
}
$scope.chartViewModel.deleteSelected();
angular.element("#deleteNodes").blur();
};
$scope.duplicateNode = function() {
if ($scope.chartViewModel.inConnectingMode) {
return;
}
var duplicatedNode = $scope.chartViewModel.duplicateSelectedNode();
// Note: node id will be used in connections to/from this duplicated node
// If id changes, connections array/obj will need to be updated as well
duplicatedNode.id = Math.floor((Math.random() * 600) + 1); // random number between 1 and 600
duplicatedNode.name = getCopyName(duplicatedNode.name);
duplicatedNode.backgroundColor = '#fff';
duplicatedNode.x = duplicatedNode.x + 15 * $scope.chartDataModel.nodes.length;
duplicatedNode.y = duplicatedNode.y + 15 * $scope.chartDataModel.nodes.length;
$scope.chartViewModel.addNode(duplicatedNode);
angular.element("#duplicateItem").blur();
};
function getCopyName(baseName) {
// Test to see if we are duplicating an existing 'Copy'
var baseNameLength = baseName.indexOf(' Copy');
if (baseNameLength === -1) {
baseNameLength = baseName.length;
}
baseName = baseName.substr(0, baseNameLength);
var filteredArray = $filter('filter')($scope.chartDataModel.nodes, {name: baseName}, false);
var copyName = baseName + " Copy" + ((filteredArray.length === 1) ? "" : " " + filteredArray.length);
return copyName;
}
});
</file>
</example>
*/
|